﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web.Script.Serialization;

namespace Entities
{
    public class NPSMarketingActivity : MasterEntitiesBase
    {
        public NPSMarketingActivity(){}

        public string sxTitle { get; set; }
        public string sxDetail { get; set; }
        public string sxLocation { get; set; }
        public int iQuota { get; set; }
        public DateTime dtmStartDate { get; set; }
        public DateTime dtmEndDate { get; set; }
        public int iNPSMarketingName { get; set; }
        public int iNPSMarketingType { get; set; }
        public NPSMarketingName oNPSMarketingName { get; set; }
        public NPSMarketingType oNPSMarketingType { get; set; }
        public List<NPSMarketingActivityAttendant> NPSMarketingActivityAttendantList;

        public string SerializeAttendantList
        {
            get
            {
                List<SearchHelper.ContactPerson> items = new List<SearchHelper.ContactPerson>();
                if (NPSMarketingActivityAttendantList.Count > 0)
                {
                    foreach (Entities.NPSMarketingActivityAttendant eventAttendant in NPSMarketingActivityAttendantList)
                    {
                        Cached.ContactPersonTable cPT = new Cached.ContactPersonTable();
                        DataTable dt = cPT.GetContactPersonList(eventAttendant.iContactPersonID);
                        if (dt.Rows.Count > 0)
                        {
                            SearchHelper.ContactPerson cp = new SearchHelper.ContactPerson();
                            cp.id = dt.Rows[0].ReadInt("customer_id");
                            cp.name = dt.Rows[0]["NAME"].ToString();
                            cp.cellphone = dt.Rows[0]["CELLPHONE"].ToString();
                            cp.gender = dt.Rows[0]["GENDER"].ToString();
                            cp.email = dt.Rows[0]["EMAIL"].ToString();
                            items.Add(cp);
                        }

                    }
                }
                else
                {
                    ////custom test 
                    //for (int i = 0; i < 5; i++)
                    //{
                    //    SearchHelper.ContactPerson cp = new SearchHelper.ContactPerson();
                    //    cp.id = i;
                    //    cp.name = "name" + i.ToString();
                    //    cp.cellphone = "cell" + i.ToString();
                    //    cp.gender = "L";
                    //    cp.email = "email" + i.ToString() + "@gmail.com";
                    //    items.Add(cp);
                    //}
                    ////
                }
                JavaScriptSerializer js = new JavaScriptSerializer();
                return js.Serialize(items);
            }
        }
    }
}